<?php
function page($pagesize, $num, $p, $url)
{
    $n=ceil($num/$pagesize);
    $previous = ($p-1)>=1?($p-1):1;
    $next = ($p+1)>$n?$n:($p+1);
    $page ='<a title="首页" href="'.$url.'page=1">首页</a>&nbsp;';
    $page .='<a title="上一页" href="'.$url.'page='.$previous.'">上一页</a>&nbsp;';
    $page .='<a title="下一页" href="'.$url.'page='.$next.'">下一页</a>&nbsp;';
    $page .='<a title="末页" href="'.$url.'page='.$n.'">末页</a>';
    return $page;
}

function ip($ip){
    return preg_replace('/(\d+)\.(\d+)\.(\d+)\.(\d+)/is',"$1.*.*.$4",$ip);
}

function msg($msg='',$url=''){
	if($url == '' && $msg <> ''){
		echo "<script type='text/javascript'>alert('{$msg}');</script>";
	}
	
	if($url <> '' && $msg <> ''){
		echo "<script type='text/javascript'>alert('{$msg}');window.location.href='{$url}'</script>";
	}
	
	if($url <> '' && $msg == ''){
		header("Location: {$url}");
		exit(0);
	}
}

function runTime($startTime){
	$startTime = explode(' ',$startTime);
	$endtime = explode(' ',microtime());
	$thistime = $endtime[0]+$endtime[1]-($startTime[0]+$startTime[1]);
	$thistime = round($thistime,5); 
	return "执行耗时：".$thistime." 秒。";
}